package com.example.administrator.easy.view;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.administrator.easy.R;
import com.example.administrator.easy.adapter.GuangVpAdapter;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/11/13.
 */

//广场
public class GuangFragment extends Fragment {//


    private TabLayout tab;
    private ViewPager vp;
    private ImageView ivSearch;

    private ArrayList<String> titleList;
    private ArrayList<Fragment> fmList;

    private GuangVpAdapter adapter;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_guang,null);
        initView(view);
        initData();
        return view;
    }


    private void initData() {
        //点击发现
        ivSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 点击发现
            }
        });



        //添加title
        titleList = new ArrayList<>();
//        View v = View.inflate(getActivity(),R.layout.fra_image_title,null);
//        ImageView iv1 = (ImageView) v.findViewById(R.id.guang_title_iv1);
//        ImageView iv2 = (ImageView) v.findViewById(R.id.guang_title_iv2);
//        ImageView iv3 = (ImageView) v.findViewById(R.id.guang_title_iv3);
//        ImageView iv4 = (ImageView) v.findViewById(R.id.guang_title_iv4);
        titleList.add("发现");
        titleList.add("直播");
        titleList.add("福利");
        titleList.add("人气");
        //添加fragment
        fmList = new ArrayList<>();
        fmList.add(new GuangFxFragment());
        fmList.add(new GuangZbFragment());
        fmList.add(new GuangFlFragment());
        fmList.add(new GuangRqFragment());

        adapter = new GuangVpAdapter(getChildFragmentManager(),titleList,fmList);
        vp.setAdapter(adapter);
        //tab和Vp的联动
        tab.setupWithViewPager(vp);
        tab.setTabTextColors(Color.rgb(159,160,160),Color.rgb(230,57,118));
        tab.setSelectedTabIndicatorHeight(2);

    }

    //初始化
    private void initView(View view) {
        tab = (TabLayout) view.findViewById(R.id.guang_tab);
        vp = (ViewPager) view.findViewById(R.id.guang_vp);
        ivSearch = (ImageView) view.findViewById(R.id.guang_iv_search);
    }
}
